package main

import "fmt"

func repeatedNTimes2(nums []int) int {
	// 找重复出现的元素即可
	m := map[int]bool{}

	for _, num := range nums {
		if m[num] {
			return num
		}
		m[num] = true
	}

	return -1
}
func repeatedNTimes(nums []int) int {
	l1, l2, l3 := -1, -1, -1
	for _, num := range nums {
		if l1 == num || l2 == num || l3 == num {
			return num
		}
		l1 = l2
		l2 = l3
		l3 = num
	}

	return -1
}

func main() {
	fmt.Println(repeatedNTimes([]int{1, 2, 3, 3}))
	fmt.Println(repeatedNTimes([]int{2, 1, 2, 5, 3, 2}))
	fmt.Println(repeatedNTimes([]int{5, 1, 5, 2, 5, 3, 5, 4}))
	fmt.Println(repeatedNTimes([]int{9, 5, 6, 9}))
}
